<template>
  <lay-form label-position="right">
    <lay-form-item label="文件">
      <lay-upload v-model="file" :drag="true" field="file" :auto="false">
        <template #preview>
          {{ file[0]?.name }}
        </template>
      </lay-upload>

    </lay-form-item>

    <lay-form-item label="类型">
      <lay-select v-model="type" placeholder="请选择">
        <lay-select-option :value="1" label="metadata"></lay-select-option>
        <lay-select-option :value="2" label="formatted-text"></lay-select-option>
        <lay-select-option :value="3" label="plain-text"></lay-select-option>
        <lay-select-option :value="4" label="main-content"></lay-select-option>
        <lay-select-option :value="5" label="structured-text"></lay-select-option>
        <lay-select-option :value="6" label="recursive-json"></lay-select-option>
      </lay-select>
    </lay-form-item>

    <lay-form-item label="操作">
      <lay-button type="primary" @click="submit">解析</lay-button>
      <lay-button @click="reset">重置</lay-button>
    </lay-form-item>
    <lay-form-item label="结果" prop="desc">
      <lay-textarea placeholder="解析结果..." v-model="result" :autosize="{minHeight: 100, maxHeight: 500}"></lay-textarea>
    </lay-form-item>
  </lay-form>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import http from './api/http';



const file = ref<any>([])
const type = ref(1)

const result = ref()

function submit() {
  console.log(type);

  console.log(file);

  http.post("/tika/parse", { file: file.value[0], code: type.value }, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  }).then(res => {
    result.value = res.data
  })
}

function reset() {
  file.value = []
  type.value = 1
  result.value = ''

}
</script>
